#include <bits/stdc++.h>

using namespace std;

class Node
{
public:
    int val;
    vector<Node *> children;

    Node() {}

    Node(int _val)
    {
        val = _val;
    }

    Node(int _val, vector<Node *> _children)
    {
        val = _val;
        children = _children;
    }
};

class Solution
{
public:
    vector<vector<int>> levelOrder(Node *root)
    {
        vector<vector<int>> res;
        queue<Node *> que;
        if (root)
        {
            que.push(root);
        }
        while (!que.empty())
        {
            vector<int> vec;
            int length = que.size();
            for (int i = 0; i < length; i++)
            {
                Node *node = que.front();
                que.pop();
                vec.push_back(node->val);
                vector<Node *> vec_node = node->children;
                for (auto ptr : vec_node)
                {
                    que.push(ptr);
                }
            }
            res.push_back(vec);
        }
        return res;
    }
};

int main()
{
    Node *root = new Node(1);
    Node *node1 = new Node(3);
    Node *node2 = new Node(2);
    Node *node3 = new Node(4);
    Node *node4 = new Node(5);
    Node *node5 = new Node(6);
    root->children.push_back(node1);
    root->children.push_back(node2);
    root->children.push_back(node3);
    node1->children.push_back(node4);
    node1->children.push_back(node5);
    Solution sol;
    vector<vector<int>> res = sol.levelOrder(root);
    for (auto vec : res)
    {
        for (auto num : vec)
        {
            cout << num << " ";
        }
        cout << endl;
    }
    return 0;
}